/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.manager.impl;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.po.FolderPO;
import com.xy.biz.fd.domain.req.folder.ListFolderRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.fd.domain.bo.FolderBO;
import com.xy.biz.fd.domain.query.FolderQuery;
import com.xy.biz.fd.domain.converter.FolderConverter;
import com.xy.biz.fd.manager.FolderManager;
import com.xy.biz.fd.dao.FolderDao;

/**
 *
 *
 * @author ssl
 * @date 2021-1-23
 */
@Service
public class FolderManagerImpl implements FolderManager {

    @Autowired
    private FolderDao folderDao;

    @Override
    public FolderBO saveFolder(FolderBO folderBO) {
        FolderPO folderPO = FolderConverter.toPO(folderBO);
        int row = folderDao.saveFolder(folderPO);
        if (row > 0) {
            return FolderConverter.fromPO(folderPO);
        }
        return null;
    }

    public static void test(){
        
    }

    @Override
    public int saveAllFolder(Collection<FolderBO> collection) {
        return folderDao.saveAllFolder(FolderConverter.toPO(collection));
    }

    @Override
    public int updateFolder(FolderBO folderBO) {
        return folderDao.updateFolder(FolderConverter.toPO(folderBO));
    }

    /**
     * 批量更新
     *
     * @param folderBOS
     */
    @Override
    public int updateFolderAll(Collection<FolderBO> folderBOS) {
        return folderDao.updateFolderAll(FolderConverter.toPO(folderBOS));
    }

    /**
     * 根据Id批量更新
     *
     * @param folderBO
     */
    @Override
    public int updateFolderByIds(FolderBO folderBO) {
        return folderDao.updateFolderByIds(FolderConverter.toPO(folderBO));
    }

    @Override
    public int updateFolderPermission(FolderBO folderBO) {
        return folderDao.updateFolderPermission(FolderConverter.toPO(folderBO));
    }

    @Override
    public int deleteFolder(Long folderId) {
        return folderDao.deleteFolder(folderId);
    }

    /**
     * 批量删除
     *
     * @param folderIds
     */
    @Override
    public int deleteFolders(Collection<Long> folderIds) {
        return folderDao.deleteFolders(folderIds);
    }

    @Override
    public FolderBO getFolder(Long folderId) {
        return FolderConverter.fromPO(folderDao.getFolder(folderId));
    }

    @Override
    public List<FolderBO> listFolderById(Collection<Long> collection) {
        return FolderConverter.fromPO(folderDao.listFolderById(collection));
    }

    @Override
    public List<FolderBO> listFolder(FolderQuery query) {
        return FolderConverter.fromPO(folderDao.listFolder(query));
    }

    @Override
    public int countFolder(FolderQuery query) {
        return folderDao.countFolder(query);
    }

    @Override
    public int updateManyFolderByParentFolderId(FolderBO folderBO) {
        return folderDao.updateManyFolderByParentFolderId(FolderConverter.toPO(folderBO));
    }

    @Override
    public List<FolderBO> listTreeFolderDocument(FolderQuery query) {
        return FolderConverter.fromPO(folderDao.listTreeFolderDocument(query));
    }

    /**
     * 根据文件夹名模糊查询文件夹
     * @param folderBO 文件夹
     * @return
     */
    @Override
    public List<FolderBO> listFolderByName(FolderBO folderBO) {
        FolderPO folderPO = FolderConverter.toPO(folderBO);
        return FolderConverter.fromPO(folderDao.listFolderByName(folderPO));
    }

    @Override
    public FolderBO getFolderByNameAndRepository(ListFolderRequest request) {
        return FolderConverter.fromPO(folderDao.getFolderByNameAndRepository(request));
    }

}
